package com.yl.applicationsecurity.controller;

import com.github.pagehelper.PageInfo;
import com.yl.applicationsecurity.pojo.ComponentUnauthorized;
import com.yl.applicationsecurity.pojo.Inspection;
import com.yl.applicationsecurity.pojo.RadarVulnerability;
import com.yl.applicationsecurity.pojo.Result;
import com.yl.applicationsecurity.service.InspectionService;
import com.yl.applicationsecurity.service.RadarVulnerabilityService;
import com.yl.applicationsecurity.service.ScriptStateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;

/**
 * @author 鹤仙问鹿仙
 * @program: Application-security
 * @description: 安全雷达发现漏洞表控制器
 * @date 2025-02-05 18:19:15
 */
@RestController
@RequestMapping("/radarVulnerability")
public class RadarVulnerabilityController {


    @Autowired
    private RadarVulnerabilityService rdarVulnerabilityService;


    @Autowired
    private ScriptStateService scriptStateService;

    @PostMapping("/list")
    public Result list(String[] nationSelect, RadarVulnerability radarVulnerability, @RequestParam(required = false) Date[] startAndEndDate, @RequestParam(defaultValue = "1", value = "pageNum")Integer pageNum
            , @RequestParam(defaultValue = "10", value = "pageSize")Integer pageSize ){
        PageInfo<RadarVulnerability> radarVulnerabilityList = null;
        if(startAndEndDate!=null&&startAndEndDate.length!=2){
            radarVulnerabilityList =  rdarVulnerabilityService.findListByRadarVulnerability(nationSelect,radarVulnerability,null,null,pageNum,pageSize);
        }else{
            radarVulnerabilityList =  rdarVulnerabilityService.findListByRadarVulnerability(nationSelect,radarVulnerability,startAndEndDate[0],startAndEndDate[1],pageNum,pageSize);
        }

        return Result.success(radarVulnerabilityList);
    }

    @RequestMapping("/updateStatus")
    public Result updateStatus(HttpServletRequest request, String[]  ids, Integer updateStatus) {

        if (rdarVulnerabilityService.updateStatus(ids, updateStatus) != 0) {
            return Result.success("修改成功");
        } else {
            return Result.error("修改失败");
        }
    }

    @PostMapping("/insert")
    public Result insert(RadarVulnerability radarVulnerability) {

        scriptStateService.updateDate("安全雷达-漏洞");
        if(rdarVulnerabilityService.insert( radarVulnerability)!=0){
            return  Result.success("添加成功");
        }else{
            return  Result.error("添加失败");
        }


    }



}

